#pragma once
#include "DXTypeDefs.h"

namespace Rendering {

class BufferManager
{
public:
	static void CreateIndexBuffer(ID3D11Device* device, size_t byteWidth, ID3D11Buffer** indexBuffer);
	static void CreateIndexBuffer(ID3D11Device* device, unsigned int numIndices, unsigned short *indexData, ID3D11Buffer **indexBuffer);

	/// <summary>Creates a vertex buffer.</summary>
	/// <param name="device">[in] Direct3D device for the buffer.</param>
	/// <param name="numVertices">[in] The number of vertices.</param>
	/// <param name="vertexData">[in] The vertices data.</param>
	/// <param name="vertexBuffer">[out] The pointer for the buffer.</param>
template<typename T>	
	static void CreateVertexBuffer(ID3D11Device* device, unsigned int numVertices, T *vertexData, ID3D11Buffer **vertexBuffer)
	{
		*vertexBuffer = nullptr;
		ID3D11BufferPtr vertexBufferInternal;

		D3D11_BUFFER_DESC VertexBufferDesc;
		VertexBufferDesc.ByteWidth = sizeof(T) * numVertices;
		VertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
		VertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
		VertexBufferDesc.CPUAccessFlags = 0;
		VertexBufferDesc.MiscFlags = 0;
		VertexBufferDesc.StructureByteStride = 0;

		D3D11_SUBRESOURCE_DATA vertexBufferData;
		vertexBufferData.pSysMem = vertexData;
		vertexBufferData.SysMemPitch = 0;
		vertexBufferData.SysMemSlicePitch = 0;

		IF_FAILED_THROW_HR(device->CreateBuffer(&VertexBufferDesc, &vertexBufferData, &vertexBufferInternal));
	
		*vertexBuffer = vertexBufferInternal.Detach();
	}

	static void CreateVertexBuffer(ID3D11Device* device, size_t byteWidth,  ID3D11Buffer **vertexBuffer);
	static void CreateConstantBuffer(ID3D11Device* device, int byteWidth, ID3D11Buffer** outBuffer);
	static int GetBufferSize(ID3D11Buffer* buffer);
};

}